//
//  ViewController.m
//  断点续传
//
//  Created by Song on 2018/5/28.
//  Copyright © 2018年 Song. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
- (IBAction)startBtn:(id)sender;
- (IBAction)zantingBtn:(id)sender;
- (IBAction)cancelBtn:(id)sender;
- (IBAction)continueBtn:(id)sender;

/**  **/
@property(nonatomic,strong) NSURLSessionDataTask *dataTask;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

// 开始下载
- (IBAction)startBtn:(id)sender {
    NSURL *url = [NSURL URLWithString:@"http://120.25.226.186:32812/resources/videos/minion_01.mp4"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    // 创建会话对象，设置代理
    NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]];
    
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request];
    self.dataTask = dataTask;
    [dataTask resume];
}

// 暂停下载
- (IBAction)zantingBtn:(id)sender {
    NSLog(@"suspend");
    [self.dataTask suspend];
}

// 取消下载
- (IBAction)cancelBtn:(id)sender {
    NSLog(@"cancel");
    [self.dataTask cancel];
}

// 继续下载
- (IBAction)continueBtn:(id)sender {
    NSLog(@"resume");
    [self.dataTask resume];
}
@end
